package com.stt.base.service;

import com.stt.base.manager.BadTaskManager;
import com.stt.base.model.Task;
import com.stt.base.model.TaskSaveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;

@Service
public class BadTaskService {

    @Autowired
    private BadTaskManager tasksManager;

    // 添加任务
    public void addTask(TaskSaveVO taskSaveVO) {
        Task task = new Task(taskSaveVO.getTaskName(), taskSaveVO.getLevel(), taskSaveVO.getTag(), new ArrayList<>());
        task.subtasks.addAll(Arrays.asList(taskSaveVO.getSubTask().split(",")));
        tasksManager.addTask(task);
    }

    /**
     * 列出优先级符合条件的任务所有任务
     * @param priority 优先级
     */
    public void listTasks(int priority) {
        // 遍历优先级≥3的任务（逻辑耦合！）
        System.out.println("高优先级任务：");
        for (Task task : tasksManager.getTasks()) {
            if (task.priority >= priority) {
                System.out.println("- " + task.title + " [优先级：" + task.priority + "]");
            }
        }
    }

    /**
     * 列出优先级符合条件的任务所有任务
     */
    public int getTaskNumber() {
       return tasksManager.getTasks().size();
    }
}
